#include <cstdio>
#include <queue>
using namespace std;
priority_queue <int> q;
int n, ans;
int main() {
	scanf ("%d", &n);
	int a;
	for (int i = 1; i <= n; i++) {
		scanf ("%d", &a);
		q.push(-a);
	}
	for (int i = 1; i < n; i++) {
		int u = q.top();
		q.pop();
		int v = q.top();
		q.pop();
		q.push(u + v);
		ans -= u + v;
	}
	printf ("%d\n", ans);
	return 0;
}
